<?php
defined ( 'BASEPATH' ) or die ( 'forbidden' );
class Sendmail_log_Controller extends Controller {
    private $areaList;    //区号列表
    private $wholeServerHost;    //全局地址

    function _init() {

        $this->type = array (
                '0' => translate ( 'SEND_2_ALL' ) ,
                '1' => translate ( 'SEND_BY_FIGHT_VALUE' ) ,
                '2' => translate ( 'SEND_BY_LEVEL' ) ,
                '3' => translate ( 'SEND_BY_ROLE_ID' ) ,
                '4' => translate ( 'SEND_ROLE_REGISTE' )
        );

        $config = get_config();
        $this->wholeServerHost = $config['host_url'];
        $server_list=get_server_list();
        foreach($server_list as $k=>$row) {
            $this->areaList[$row['SvrOutAddr']] = $row['SvrID']."-".$row['SvrName'][1];
        }
    }

    function index() {
        $this->view->display ( "seal/mail/index" );
    }

    function flexigrid() {
        list ( $colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page ) = $this->common->get_flexigrid_params ();
        $sql = "SELECT COUNT(id) AS num FROM mail_sendlog2 WHERE {$where}";
        $one = $this->db->one ( $sql );
        $total = $one ['num'];
        $orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
        $sql = "SELECT {$colsinfo} FROM mail_sendlog2 WHERE {$where}";
        $this->db->query ( $sql );
        while ( $n = $this->db->get_array () ) {
            $n ['mailtype'] = $this->type [$n ['mailtype']];
            $row [] = array (
                    'id' => $n ['id'],
                    'cell' => $n 
            );
        }
        $result = array (
                'page' => $page,
                'total' => $total,
                'rows' => $row 
        );
        echo json_encode ( $result );
    }

    function add() {
        if (is_submit ()) {
            $rowdata = $_POST ['row'];
            //var_dump($rowdata);
            $game_host=$rowdata['area'];
            $rowdata['area']=json_encode($rowdata['area']);
            
            $result = $this->db->insert( 'mail_sendlog2', $rowdata);
            if ( $result  ) {
                   cp_tips ( "success" );
            } else {
                $result = translate ( 'C_TIPS_ERROR_TEXT' );
                error ( $result );
            }
        }

        $this->view->assign("arealist", $this->areaList);
        $this->view->display ( "seal/mail/send" );
    }

    function edit($id = 0) {

    }

    function del($id = 0) {

    }
    
    function multi() {

    }
}


?>
